#include "DrawShapeApp.h"

void DrawShapeApp::Run() //runs the heart of the program
{
	unsigned int l_option = 0;
	bool withHiding = true, withTransfer = true;
	Menu menu(1);
	Menu third_menu(3);
	
	while ( l_option != menu.getExitOptionNum())
	{
		l_option = menu.choose();
		switch(l_option)
		{
			case 1:
				clrscr();
				int tmp;
				tmp = third_menu.choose();
				if(tmp == 1) //rectangle
				{
					MyRectangle *rect;
					rect = new MyRectangle;
					m_shapeCon.addShapeToList(rect);
				}
				else if(tmp == 2) //circle
				{
					MyCircle *circ;
					circ = new MyCircle;
					m_shapeCon.addShapeToList(circ);
				}
				else
				{
					cout << "Wrong option, please choose 1 or 2";
					_getch();
					l_option = menu.choose();
				}
				break;

			case 2:
				clrscr();
				m_shapeCon.drawList( withHiding);
				_getch();
				break;

			case 3:
				if(withHiding)
				{
					withHiding = false;
					menu.changeOption(2,"Draw With Cuts");
					menu.changeOption(3,"Change default drawing option to Draw With Hiding");
				}
				else
				{
					withHiding = true;
					menu.changeOption(2,"Draw With Hiding");
					menu.changeOption(3,"Change default drawing option to Draw With Cuts");
				}
				break;

			case 4:
				chooseShape(withHiding);
				break;

			case 5:
				scr_app.run(m_shapeCon,withTransfer);
				break;

			case 6:
				scr_app.run(m_shapeCon,!withTransfer);
				break;
		}
	}
}

void DrawShapeApp::chooseShape(bool withHiding)//recievs a point from the user and finds a containig rectangle
{
	int x,y;
	cout << "enter the point to find the Shape[x y]: ";
	cin >> x >> y;
	list<Shape*>::iterator itr = m_shapeCon.findContainingShape(x,y);
	clrscr();
	if (itr == m_shapeCon.getEndOfList() )
	{
		cerr << "there is no shape containing this point.";
		_getch();
		clrscr();
		m_shapeCon.drawList(withHiding);
		gotoxy(x,y);
		cout << '@';
		_getch();
	}
	else
	{
		m_shapeCon.drawList(withHiding);
		(*itr)->drawWithHiding('+');
		gotoxy(x,y);
		cout << '@';
		_getch();
		secondaryRun(itr,withHiding);
	}
}

void DrawShapeApp::secondaryRun(list<Shape*>::iterator itr,bool withHiding)//if a shape is chosen the program shifts to a secondary menu.
{
	Menu secondary_menu(2);
	int l_option = secondary_menu.choose();

	switch(l_option)
	{
	case 1:
		m_shapeCon.drawList(withHiding);
		_getch();
		break;

	case 2:
		m_shapeCon.deleteShape(itr);
		clrscr();
		m_shapeCon.drawList(withHiding);
		_getch();
		break;

	case 3:
		m_shapeCon.bringToFront(itr);
		clrscr();
		m_shapeCon.drawList(withHiding);
		_getch();
		break;

	case 4:
		m_shapeCon.moveToBack(itr);
		clrscr();
		m_shapeCon.drawList(withHiding);
		_getch();
		break;

	case 5:
		(*itr)->moveShape();
		clrscr();
		m_shapeCon.drawList(withHiding);
		_getch();
		break;
	case 6:
		(*itr)->assignAnimationValues();
		break;
	}
}

